<template>
  <!-- 图纸目录清单 -->
  <base-breadcrumb>
    <searchData :searchData="searchArr" @search="search"></searchData>
    <a-card>
      <div>
        <a-button class="mb12" v-btnPermission="'tm_023_add_01'" type="primary" icon="plus" @click="handleManage(2)"
          >新增</a-button
        >
      </div>
      <list-table
        ref="table"
        size="default"
        rowKey="key"
        :page-keys="['pageNum', 'pageSize','totalSize']"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <template slot="operation" slot-scope="text, record">
          <MoreButton>
          <a v-btnPermission="'tm_023_loo_04'" @click="handleManage(0, record)">查看</a>
          
          <!-- 编辑 -->
          <span
            v-btnPermission="'tm_023_wre_05'"
            v-if="record.checkReasonFlag"
          >
            <a-divider type="vertical" />
            <a   @click="handleManage(0, record,true)">填写未复核原因</a>
          </span>
          <span
            v-btnPermission="'tm_023_edi_02'"
            v-if="record.auditStatus != 'SUBMITTED' && record.auditStatus != 'PAST'"
          >
            <a-divider type="vertical" />
            <a @click="handleManage(1, record)">编辑</a>
          </span>
          <!-- 删除 -->
          <span
            v-if="record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED'"
            v-btnPermission="'tm_023_del_03'"
          >
            <a-divider type="vertical"></a-divider>
            <a @click="handleRemoveParams({ id: record.id })">删除</a>
          </span>

          <span
            v-btnPermission="'tm_023_loo_04'"
            v-if="
              record.auditStatus === 'PAST' || record.auditStatus === 'SUBMITTED' || record.auditStatus === 'REJECTED'
            "
          >
            <a-divider type="vertical" />
            <approval-button :status="record.auditStatus" :id="record.id"></approval-button>
          </span>
            </MoreButton>
        </template>
        <span slot="auditStatus" slot-scope="text, record">
          <list-status :status="record.auditStatus" :isApproval="true" conversion="en" :text="text"></list-status>
        </span>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import BasePage from '@/views/basePage' // 基础配置
import { getPageTechnicalMonthPlan, deltechnicalMonthPlan } from '@/api/technical/technicalReview'

import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { status } from '../model.js'
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '月份',
    dataIndex: 'month'
  },
  {
    title: '所属分公司',
    dataIndex: 'branchComName'
  },
  {
    title: '所属项目',
    dataIndex: 'projectName',
    width: '300px',
    ellipsis: true
  },
  {
    title: '填报人',
    dataIndex: 'modifiedName'
  },
  {
    title: '填报时间',
    dataIndex: 'createTime'
  },
  {
    title: '状态',
    dataIndex: 'auditStatus',
    scopedSlots: { customRender: 'auditStatus' }
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: '230px',
    scopedSlots: { customRender: 'operation' }
  }
]
const searchArr = [
  // {
  //   name: '所属分公司',
  //   valueKey: 'branchComId',
  //   type: SelectSubCompany
  // },
  {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
  // {
  //   name: '所属项目',
  //   keyValue: 'branchComId',
  //   valueKey: 'projectId',
  //   type: SelectProject
  // },
  {
    name: '月份',
    type: 'month',
    value: 'month',
    attrs: {
      valueFormat: 'YYYY-MM'
    }
  },
  {
    name: '填报人',
    value: 'modifiedName',
    type: 'input'
  },
  {
    name: '填报时间',
    type: 'dateRange',
    value: 'activityDate',
    attr: {
      rangeFormat: ['modifiedStartTime', 'modifiedEndTime']
    }
  }
]

import { STable } from '@/components'
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    STable
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {},
      removeApi: {
        remove: deltechnicalMonthPlan
      }, // api
      loadData: async parameter => {
        const requestParameters = Object.assign({}, parameter, { param: this.queryParam })
        //  currentPage: 'currentPage',
        //                     totalSize: 'totalSize',
        return getPageTechnicalMonthPlan(requestParameters).then(res => {
          if (res.code === '0') {
            res.data.list.forEach(i => {
              i.auditStatus = status[i.auditStatus]
            })
            return {
              code: 200,
              data: res.data.list,
              totalSize: res.data?.total,
              currentPage: res.data?.pageNum
            }
          }
        })
      }
    }
  },
  methods: {
    //搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(type, record,isReason) {
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
        query.month = record.month
        query.branchComId = record.branchComId
        query.projectId = record.projectId
      }
      console.log('isReasonisReason',isReason)
      if (isReason){
        query.isReason = isReason
      }
      this.$router.push({
        name: 'updateMonthlyPlan',
        query
      })
    }
  }
}
</script>
